# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")

auto_setup(__file__)

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)


#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')

using(scriptRoot + "common.air")
from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:
    sleep(1.0)
    openKoufu()
    sleep(1.0)
    openScene("jiayou")
    
    ##先睡10s
    sleep(10.0)
    touch(Template(r"tpl1681111432184.png", record_pos=(-0.002, 0.264), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681111452743.png", record_pos=(-0.359, 0.176), resolution=(1080, 1920)))
    sleep(1.0)
    #划上来
    width, height = device().get_current_resolution()
    start_pt = (width/2, height*0.9)
    end_pt = (width/2, height*0.4)
    swipe(start_pt, end_pt, duration=1)
    sleep(1.0)
    touch(Template(r"tpl1681111519890.png", record_pos=(-0.34, 0.641), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681111537945.png", record_pos=(-0.003, 0.82), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681111558612.png", record_pos=(0.198, 0.237), resolution=(1080, 1920)))
    sleep(5.0)
    
    assert_exists(Template(r"tpl1681978740991.png", record_pos=(-0.274, 0.734), resolution=(1080, 1920)), "验证是否跳回我们的收银台")

    

except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')




